
//
//
//
//
import java.util.*;
import java.io.*;

public class Looper extends Timer {

	float f_start = 0.0f;
	float f_end = 1.0f;
	int length_ms;
	String s_start = new String("0.0");
	Timer t;
	PrintWriter pw;
	
	public Looper(float start, int ms, PrintWriter p) {
		t = new Timer(true);
		f_start = start;
		s_start = s_start.valueOf(f_start);
		length_ms = ms;
		pw = p;
		
	}
	public Looper(float start, float end, PrintWriter p) {
		t = new Timer(true);
		f_start = start;
		s_start = s_start.valueOf(f_start);
		length_ms = (int)((end - start) * 1000);
		pw = p;
	}
	
	public void begin() {
		t.schedule(new Loop(), 0, length_ms);
	}
	public void end() {
		t.cancel();
		t.purge();
	}
	
////////////////  inner class  //////////////////
	class Loop extends TimerTask {
		public void run() {
			try {
				pw.print("seek -1000000\n");  // seek back to beginning (no matter how long it is)
				pw.print("seek " + s_start + "\n");
				pw.flush();  // you have to do this or it won't really get sent out!
				//System.out.println("Just wrote something");
			}
			catch(Exception e) {
				System.out.println("Exception in Loop (inner class) in Looper class");
				System.out.println(e.getMessage());
				e.printStackTrace();
			}
		}
	}	
//////////////  end inner class /////////////////

}

